﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Entity;
using BLL;

namespace Web.admin.InnerManage
{
    public partial class AddInnerBuget : System.Web.UI.Page
    {
        MoneyService moneyService = new MoneyService();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                string operation = Request["OPERATION"];
                if (operation == null)
                {
                    string contestId = Request["ContestId"];
                    ContestId.Value = contestId;
                    return;
                }
                string moneyId = Request["id"];
                if (moneyId == null)
                    return;

                if (operation == "Modify")
                {
                    ModifyMoney(moneyId);
                }
                else if (operation == "Delete")
                {
                    DeleteMoney(moneyId);
                }
            }
        }

        protected void ModifyMoney(string moneyId)
        {
            MoneyId.Value = moneyId;

            BoMoney money = moneyService.GetMoney(moneyId);

            txtItem.Text = money.MON_ITEM;
            txtComment.Text = money.MON_COMMENT;
            txtMoney.Text = money.MON_NUMBER.ToString();
            
        }

        protected void DeleteMoney(string teacherId)
        {
            
        }

        protected void btn_Save_Click(object sender, EventArgs e)
        {
            BoMoney money = null;
            if (MoneyId.Value == "")
            {
                money = new BoMoney();
                money.MON_CONTESTS = ContestId.Value;
            }
            else
                money = moneyService.GetMoney(MoneyId.Value);

            money.MON_ITEM = txtItem.Text;
            money.MON_COMMENT = txtComment.Text;
            money.MON_NUMBER = Double.Parse(txtMoney.Text);

            if (MoneyId.Value == "")
                moneyService.CreateBuget(money);
            else
                moneyService.UpdateMoney(money);

            Response.Redirect("InnerBuget.aspx?id=" + money.MON_CONTESTS);
        }
    }
}